package homework.test3;

import java.util.ArrayList;
import java.util.Iterator;

/*
//使用ArrayList 对象存储Student对象并遍历 三种方式
 */
public class Demo3 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();

        Student stu1 = new Student("张三",23);
        Student stu2 = new Student("李四",21);
        Student stu3 = new Student("王五",33);

        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        //循环
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu);
        }
        System.out.println("-----------------------");

        //迭代器
        Iterator<Student> it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        System.out.println("-----------------------");

        //增强for
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
